<template>
  <div class="page">
    <!-- header -->
    <van-nav-bar
      :z-index="999"
      :fixed="true"
      left-arrow
      @click-left="onClickLeft"
      :placeholder="true"
      title="顺序练习"
    ></van-nav-bar>
    <div class="app-page">
      <div class="sequ-wrap">
        <div class="sequ-card">
          <div class="sequ-title">目前练习情况</div>
          <div class="sequ-row justify">
            <div class="hd">未作</div>
            <div class="val">{{ notDone }}</div>
          </div>
          <div class="sequ-row justify">
            <div class="hd">错题</div>
            <div class="val">{{ errors }}</div>
          </div>
          <div class="sequ-row justify">
            <div class="hd">累计练习</div>
            <div class="val">{{ appUp }}</div>
          </div>
          <div class="mnks-btns">
            <van-button
              @click="href('/PracticeQuestions')"
              type="primary"
              block
              round
              >开始练习</van-button
            >
            <!-- <van-button to="/PracticeQuestions" type="primary" block round plain
              >精简500题</van-button
            > -->
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "SequentialExam",
  data() {
    return {
      text: "",
      notDone: 0, // 未做
      errors: "0", // 做错
      appUp: 0, // 累计练习
      all: 0, // 全部的题
      haveFinished: 0 // 已做的题
    };
  },

  mounted() {
    this.notDone = 0;
    this.appUp = 0;
    this.errors = 0;
    // 错题
    if (this.$route.params.type == "1") {
      if (localStorage.getItem("errors")) {
        this.errors = localStorage.getItem("errors");
      } else {
        this.errors = 0;
      }
      // 累计练习
      if (localStorage.getItem("grandTotal") == "") {
        let grandTotal = parseInt(localStorage.getItem("grandTotal"));
        this.appUp = grandTotal;
      } else {
        this.appUp = 0;
        localStorage.setItem("grandTotal", this.appUp);
      }
      if (localStorage.getItem("haveFinished")) {
        let yizuo = parseInt(localStorage.getItem("haveFinished"));
        this.appUp = yizuo + parseInt(localStorage.getItem("grandTotal"));
        localStorage.setItem("grandTotal", this.appUp);
      } else if (localStorage.getItem("grandTotal") == "") {
        let grandTotal = parseInt(localStorage.getItem("grandTotal"));
        this.appUp = grandTotal;
      } else {
        this.appUp = 0;
      }

      // 未做
      if (localStorage.getItem("haveFinished")) {
        this.haveFinished = parseInt(localStorage.getItem("haveFinished"));
      }
      if (localStorage.getItem("all")) {
        this.all = parseInt(localStorage.getItem("all"));
      }
      if (this.all - this.haveFinished < 0) {
        this.notDone = 0;
      } else {
        this.notDone = this.all - this.haveFinished;
      }
    } else {
      if (localStorage.getItem("errors4")) {
        this.errors = localStorage.getItem("errors4");
      } else {
        this.errors = 0;
      }
      // 累计练习
      if (localStorage.getItem("grandTotal4") == "") {
        let grandTotal = parseInt(localStorage.getItem("grandTotal4"));
        this.appUp = grandTotal;
      } else {
        this.appUp = 0;
        localStorage.setItem("grandTotal4", this.appUp);
      }
      if (localStorage.getItem("haveFinished4")) {
        let yizuo = parseInt(localStorage.getItem("haveFinished4"));
        this.appUp = yizuo + parseInt(localStorage.getItem("grandTotal"));
        localStorage.setItem("grandTotal4", this.appUp);
      } else if (localStorage.getItem("grandTotal4") == "") {
        let grandTotal = parseInt(localStorage.getItem("grandTotal4"));
        this.appUp = grandTotal;
      } else {
        this.appUp = 0;
      }

      // 未做
      if (localStorage.getItem("haveFinished4")) {
        this.haveFinished = parseInt(localStorage.getItem("haveFinished4"));
      }
      if (localStorage.getItem("all4")) {
        this.all = parseInt(localStorage.getItem("all4"));
      }
      if (this.all - this.haveFinished < 0) {
        this.notDone = 0;
      } else {
        this.notDone = this.all - this.haveFinished;
      }
    }

    // localStorage.removeItem("grandTotal");
    // localStorage.removeItem("errors");
    // localStorage.removeItem("haveFinished");
    // localStorage.removeItem("all");
    // //  localStorage.removeItem("grandTotal")
    // localStorage.removeItem("errors4");
    // localStorage.removeItem("haveFinished4");
    // localStorage.removeItem("all4");
  },

  methods: {
    onClickLeft() {
      this.$router.go(-1); //返回上一层
    },
    href(url) {
      // console.log(this.$route.params.type);
      this.$router.push({ path: url + "/" + this.$route.params.type });
    }
  },
  created() {
    let dsBridge = require("dsbridge");
    dsBridge.call("goBack", "", function() {
      history.go(-1);
    });
  }
};
</script>
<style></style>
